#pragma once

#include "list"
#include "string"
#include "map"
using namespace std;

typedef list<pair<wstring, int> > FILELIST;
typedef list<wstring> WSTRINGLIST;
typedef map<int, int> LINELIST;

enum FilterRule
{
	eRuleExclude,
	eRuleIncludeOnly,
};

enum CoverageType
{
	eNotCovered = 0,
	ePartiallyCovered = 1,
	eCovered = 2,
};

typedef struct tagCoverageData
{
	int nLinesCovered;
	int nLinesPartiallyCovered;
	int nLinesNotCovered;
	int nBlocksCovered;
	int nBlocksNotCovered;
}COVERAGE_DATA;

class CParseCoverageData
{
public:
	CParseCoverageData(void);
	~CParseCoverageData(void);

public:
	void Open(LPCTSTR lpszFilePath);
	void Close();
	//filters: used to filter files.
	//filterType: defines FilterRule. eRuleExclude - exclude all files which contain string in filters
	// eRuleInclude - include only files which contain string in filters
	// The rule is case sensitive.
	void ListFiles(FilterRule filterType, WSTRINGLIST& filters, FILELIST& outFiles);
	void GetFileCoverage(const wstring& sFilePath, int nFileID, LINELIST& lines, COVERAGE_DATA* pCoverage = NULL);

protected:
	wstring GetFirstChildValue(WCHAR* lpStart, WCHAR* lpEnd, const wstring& sTagBegin, const wstring& sTagEnd);
	BOOL CheckFilter(const wstring& sFilePath, FilterRule filterType, WSTRINGLIST& filters);
	void EnumerateLines(WCHAR* lpStart, WCHAR* lpEnd, LINELIST& lines);

protected:
	HANDLE m_hFile;
	LPVOID m_pHead;
};
